package com.tianqu.tms.www.car.action;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAjaxAction;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.entity.MarketCarGateInfo;


/** 
 * 道闸更新信息查询
 * @author mufeiyu
 */
public class CarSelectDBDateUpdateAjaxAction extends TmsAjaxAction{
	private Logger logger = Logger.getLogger(CarSelectDBDateUpdateAjaxAction.class);
	private static final String GATEID1 = "gateId1";
	private static final String GATEID2 = "gateId2";
	private static final String INSERTTIMES1 = "insertTimes1";
	private static final String INSERTTIMES2 = "insertTimes2";
	@Override
	public void process(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws TmsException {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = TxController.getTxController();
		controller.begin();
		String gateId1 = request.getParameter(GATEID1);
		String gateId2 = request.getParameter(GATEID2);
		String insertTimes1 = request.getParameter(INSERTTIMES1);
		String insertTimes2 = request.getParameter(INSERTTIMES2);
		
		MarketCarGateInfo gateInfo = new MarketCarGateInfo();
		List<MarketCarGateInfo> gateInfoList1 = new ArrayList<MarketCarGateInfo>();
		List<MarketCarGateInfo> gateInfoList2 = new ArrayList<MarketCarGateInfo>();
		if(!"0".equals(gateId1)&&!StringUtil.isNullOrBlank(gateId1)){
			gateInfoList1 = gateInfo.findGateInfoListByGateId(Integer.valueOf(gateId1),insertTimes1);
		}else if(!"0".equals(gateId2)&&!StringUtil.isNullOrBlank(gateId2)){
			gateInfoList2 = gateInfo.findGateInfoListByGateId(Integer.valueOf(gateId2),insertTimes2);
		}
		//拼select
		StringBuffer str = new StringBuffer();
		if(gateInfoList1.size()>0){
			str.append(gateId1);
		}else {
			str.append("0");
		}
		str.append("##");
		if(gateInfoList2.size()>0){
			str.append(gateId2);
		}else {
			str.append("0");
		}

		String responseText =str.toString();
		controller.commit();
		responseValues(response, responseText, TEXT);
		
		logger.debug(this.getClass().getName() + "#doAction was completed.");
	}

}
